// custom-tab-bar/index.js
Component({
  /**
   * 组件的初始数据
   */
  data: {
    active: '',
    list: [
      {
        normal: '../assets/tab/home.png',
        active: '../assets/tab/home-active.png',
        text: '工作台',
        url: '/pages/index/index'
      },
      {
        normal: '../assets/tab/task.png',
        active: '../assets/tab/task-active.png',
        text: '患者',
        url: '/pages/patient/index'
      },
      {
        normal: '../assets/tab/todo.png',
        active: '../assets/tab/todo-active.png',
        text: '任务',
        url: '/pages/task/index'
      },
      {
        normal: '../assets/tab/user.png',
        active: '../assets/tab/user-active.png',
        text: '我的',
        url: '/pages/account/index'
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      wx.switchTab({
        url: this.data.list[event.detail].url
      });
    },
    init() {
      const page = getCurrentPages().pop();
      this.setData({
        active: this.data.list.findIndex(item => item.url === `/${page.route}`)
      });
    }
  }
})